package com.csw.encryptiontechnology.linux;

import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("docker")
public class DockerInstaller {

    public static void main(String[] args) throws Exception {
        //LinuxUtils.installDocker("192.168.147.131", 22, "root", "111");
        //LinuxUtils.mysqlInstall("192.168.147.132", 22, "root", "111");


        Session session = LinuxUtils.getSession("192.168.147.132", 22, "root", "111");
//        LinuxUtils.readLog(session, "docker logs csw_mysql_003");

        //LinuxUtils.readLogTail("192.168.147.132", 22, "root", "111", "/var/log/mysql/mysql.log");
        LinuxUtils.mysqlInstallMany(session);

        String upperCase = "dz5f1k8vru2o";
        //进入数据库1容器
//        LinuxUtils.runCommand(session, "docker exec -it project_name_" + upperCase + "-master-1 bash", "执行启动命令：");
//        //进入数据库1
//        LinuxUtils.runCommand(session, "mysql  -uroot -p" + upperCase, "执行启动命令：");
        //查看状态
        //LinuxUtils.runCommandShell(session, "docker exec -it project_name_" + upperCase + "-master-1 bash -c \"mysql  -uroot -p" + upperCase + " -e 'SHOW MASTER STATUS\\G' | grep Position \" ;", "执行启动命令：");
        //LinuxUtils.runShell(session, "sh /position.sh\n", "执行启动命令：");

//        List<String> runCommandList = new ArrayList<>();
//        runCommandList.add("docker exec -it project_name_" + upperCase + "-master-1 bash");
//        runCommandList.add("mysql  -uroot -p" + upperCase + "");
//        runCommandList.add("SHOW MASTER STATUS \\G | grep Position");
//        LinuxUtils.runCommand3(session, runCommandList, "执行启动命令：");
        //LinuxUtils.runCommand(session, "docker ps -a", "执行启动命令：");
        session.disconnect();

    }

    @GetMapping("mysqlMany")
    public void mysqlMany() throws JSchException {
        Session session = LinuxUtils.getSession("192.168.147.132", 22, "root", "111");
        LinuxUtils.mysqlInstallMany(session);
    }

}